package com.fjnu.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fjnu.controller.common.BaseController;
import com.fjnu.entities.Unit;
import com.fjnu.service.IUnitService;
import com.fjnu.service.impl.UnitService;


@Controller
@RequestMapping(value="/user")
public class UnitController extends BaseController{
	private static Logger logger =LogManager.getLogger(UnitController.class);
	@Autowired
	private IUnitService unitService;
	@ResponseBody
	@RequestMapping(value="/findunit")
	public Map<String,Object> findUnit(){
		logger.info("查询单位信息列表");
		if(!init().get(STATUS).equals(SUCCESS))
			return getData2Result();
		List<Unit> list = unitService.findUnit();
		//Map<String,Object> map= new HashMap<String, Object>();
		put("data", list);
		//map.put("success", true);
		return getData2Result();
		
	}
	@RequestMapping(value="/saveUnit")
	@ResponseBody
	public Map<String,Object> saveUnit(@RequestBody Unit unit){
		logger.info("添加新单位信息");
		if(!init().get(STATUS).equals(SUCCESS))
			return getData2Result();
		unitService.saveUnit(unit);
		return getData2Result();
	}
	@RequestMapping(value="/delUnit")
	@ResponseBody
	public Map<String,Object> delUnit(int id){
		logger.info("删除ID为 "+id+" 的单位信息");
		if(!init(id).get(STATUS).equals(SUCCESS))
			return getData2Result();
		unitService.delUnit(id);
		//Map<String,Object> map = new HashMap<String,Object>();
		//map.put("success", true);
		return getData2Result();
 }	
}
